﻿using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;

// 敌人的移动状态
public class EnemyChaseState:IEnemyState
{
    public EnemyChaseState(EnemyFSMSystem fsm, ICharacter c):base(fsm,c)
    {
        mStateID = EnemyStateID.Chase;
    }
    private Vector3 mTargetPosition;
    public override void DoBeforeEntering()
    {
        mTargetPosition = GameFacade.Insance.GetEnemyTargetPosition();
    }

    // 状态转移
    public override void Reason(List<ICharacter> targets)
    {
        if (targets != null && targets.Count > 0)
        {
            float distance = Vector3.Distance(mCharacter.position, targets[0].position);
            if (distance <= mCharacter.atkRange)
            {
                mFSM.PerformTransition(EnemyTransition.CanAttack);
            }
        }
    }
    
    // 状态行为
    public override void Act(List<ICharacter> targets)
    {
        if (targets != null && targets.Count > 0)
        {
            mCharacter.MoveTo(targets[0].position);
        } else
        {
            mCharacter.MoveTo(mTargetPosition);
        }
    }
}
